using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Multiplicity.Reflection {

    public sealed class GuidHeap : StorageHeap<Guid> {

        public const string Name = "#GUID";

        const uint SizeOfGuid = 16;

        readonly uint guidCount;

        internal GuidHeap(Module module, StorageHeapHeader head, long storageOffset)
            : base(module, head, storageOffset) {
 
            this.guidCount = Header.Size / SizeOfGuid;
        }
        
        protected override bool IsValidIndex(uint index) {
            return index > 0 && index <= guidCount;
        }

        protected override Guid ReadItem(uint index) {
            long idx = Convert.ToInt32(BufferOffset + ((index - 1) * SizeOfGuid));
            byte[] bytes = new byte[SizeOfGuid];
            
            Array.Copy(Buffer, idx, bytes, 0, bytes.Length);
            return new Guid(bytes);
        }

    }

}
